#ifndef __I2C_CFG_H__
#define __I2C_CFG_H__

#include "Common.h"

/***********************************************************************************************\
* Public macro definitions
\***********************************************************************************************/
#define DEBUG	0
//#define POLLING_MODE	1

#define I2C_MASTER_ADDR		0x01
#define I2C_SLAVE_ADDR 		0x1D

/* PCR PORTS definitions for I2C0 */
#ifdef MCU_MKL25Z4

#define I2C__SCL0_PCR		PORTE_PCR24 /*PTE24 as SCL */
#define I2C__SDA0_PCR		PORTE_PCR25 /*PTE25 as SDA */	
#else
#define I2C__SCL0_PCR		PORTB_PCR3 /*PTB3 as SCL */
#define I2C__SDA0_PCR		PORTB_PCR4 /*PTB4 as SDA */	
#endif


/* PCR PORTS definitions for I2C1 */
#ifdef MCU_MKL25Z4

#define I2C__SCL1_PCR		PORTE_PCR24 /*PTE24 as SCL */
#define I2C__SDA1_PCR		PORTE_PCR25 /*PTE25 as SDA */	
#else
#define I2C__SCL1_PCR		PORTB_PCR3 /*PTB3 as SCL */
#define I2C__SDA1_PCR		PORTB_PCR4 /*PTB4 as SDA */	
#endif


/* MUX control for I2C0 */
#ifdef MCU_MKL25Z4
#define I2C__SCL0_MUX		(5u)
#define I2C__SDA0_MUX		(5u)
#else
#define I2C__SCL0_MUX		(2u)
#define I2C__SDA0_MUX		(2u)
#endif
/* MUX control for I2C1 */
#ifdef MCU_MKL25Z4
#define I2C__SCL1_MUX		(5u)
#define I2C__SDA1_MUX		(5u)
#else
#define I2C__SCL1_MUX		(2u)
#define I2C__SDA1_MUX		(2u)
#endif

#define I2C__nChannel0		((uint8)0x00)
#define I2C__nChannel1		((uint8)0x01)

#define I2C_nTXEvent    (0u)
#define I2C_nRXEvent    (1u)

#define I2C__nAccelChann	(0x00)


#define printf		UART0_vWriteString

/***********************************************************************************************\
* Public type definitions
\***********************************************************************************************/
typedef enum{
	/*Touch Driver ID*/
	I2C_enTouchDev = 0,
	/*Accelerometer ID*/
	I2C_enAccelDev,
	/*i2c Memory ID*/
	I2C_enMemDev,
	/*Max Number of Devices*/
	I2C_enNumOfDevices	
}I2C_tenDevices;

/***********************************************************************************************\
* Public prototypes
\***********************************************************************************************/

   /**
    * This function is for System Level Module initialization   
    * @param void
    * @return void	
    */
   void I2C_vSini(void);
   
   
   /**
    * This function is for HW Level Module initialization   
    * @param u8channel I2C channel
    * 			u8Addr Slave address
    * 			u32bps Bits per Second 
    * @return void	
    */
   void I2C_vInitHW(uint8 u8channel, uint8 u8Addr, uint32 u32bps);
   
   
   /**
    * Handler event function for Finish transmission on channel 0  
    * @param void
    * @return void	
    */
   void I2C_Chann0TxFinishHandler(void);
   
   /**
    * Handler event function for Finish transmission on channel 1   
    * @param void
    * @return void	
    */
   void I2C_Chann1TxFinishHandler(void);
   
   /**
    * Handler event function for Finish reception on channel 0  
    * @param void
    * @return void   
    */
   void I2C_Chann0RxFinishHandler(void);
   
   /**
    * Handler event function for Finish reception on channel 1    
    * @param void
    * @return void   
    */
   void I2C_Chann1RxFinishHandler(void);
   
   /**
    * Function for start a Read job in a configured device    
    * @param tenDevice ID of the selected device 
    * 		  u8StartAddr Star Address for reading job 
    * 		  u8nBytes 	Number of byte to be read
    * @return void	
    */
   void I2C_ReadJob(I2C_tenDevices tenDevice, uint8 u8StartAddr, uint8 u8nBytes, uint8 *u8buffPtr);
   
   /**
    * Function for start a Write job in a configured device  
    * @param tenDevice ID of the selected device
    *  	  u8StartAddr Start Address for the Write job
    *  	  *u8Buffptr Pointer to a buffer that contains the data for transmission
    *  	  u8Bytes  Number of Bytes to be Write. *  	  
    * @return void	
    */
   void I2C_WriteJob(I2C_tenDevices tenDevice, uint8 u8StartAddr, uint8 *u8Buffptr, uint8 u8nBytes);
   
   /**
    * Interface to get the state of a device.  
    * @return bool: device state, True,False 
    * @author Misael Munoz
    * @param  tenDevice: ID of the device 
    */
   bool I2C_bDeviceBusy(I2C_tenDevices tenDevice);
   
   
   

#endif
